const {DataTypes} = require('sequelize')

const seq = require('../db/seq')
const Goods = require('./goods.model')

const Cart = seq.define('zd_carts', {
    goods_id: {
        type: DataTypes.INTEGER,
        allowNull: false,
        comment: '商品id'
    },
    user_id: {
        type: DataTypes.INTEGER,
        allowNull: false,
        comment: '用户id'
    },
    number:{
        type: DataTypes.INTEGER,
        allowNull: false,
        defaultValue: 1,
        comment: '商品数量'
    },
    selected:{
        type: DataTypes.BOOLEAN,
        allowNull: false,
        defaultValue: true,
        comment: '是否选中'
    }
})

// Cart.sync({force: true})

//设置表关联(一对一关系，外键在当前这个表里用belongsTo)
Cart.belongsTo(Goods,{
    foreignKey: 'goods_id',//外键
    as: 'goods_info'//设置别名，即将Goods模型的实例挂载到Cart模型的实例上时，使用"goods_info"来访问
})

module.exports = Cart;